package service;

import util.IOUtil;

import java.io.File;
import java.io.IOException;

/**
 * @program: hw
 * @description: qiuheyi
 * @author: qhy
 * @create: 2020-08-10 09:08
 **/
public class IOUtilService {

    public void testPrintHex() {
        try {
            IOUtil.printHex("D:\\Javaio\\FileUtils.java");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void testPrintHexByByteArray() {
        try {
            long start = System.currentTimeMillis();//当前时间与协调世界时 1970 年 1 月 1 日午夜之间的时间差（以毫秒为单位测量）
            //IOUtil.printHexByByteArray("e:\\javaio\\FileUtils.java");
            //IOUtil.printHex("e:\\javaio\\1.mp3");
            IOUtil.printHexByByteArray("/Users/qiuheyi/Downloads/死了都要爱.mp3");
            System.out.println();
            long end = System.currentTimeMillis();
            System.out.println(end - start);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        testPrintHexByByteArray();
    }

    public void testCopyFile() {
        try {
            IOUtil.copyFile(new File("d:\\javaio\\1.txt"), new File("d:\\javaio\\1copy.txt"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void testCopyFileByBuffer() {
        try {
            long start = System.currentTimeMillis();
           /*IOUtil.copyFileByByte(new File("e:\\javaio\\1.mp3"), new File(
             "e:\\javaio\\2.mp3"));*/  //两万多毫秒
           /*IOUtil.copyFileByBuffer(new File("e:\\javaio\\1.mp3"), new File(
             "e:\\javaio\\3.mp3"));//一万多毫秒*/
            IOUtil.copyFile(new File("e:\\javaio\\1.mp3"), new File(
                    "e:\\javaio\\4.mp3"));//7毫秒
            long end = System.currentTimeMillis();
            System.out.println(end - start);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
